<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增配件管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-parts-add">
            <input name="partsType" type="hidden" id="treeId"/>
            <input name="factoryId" type="hidden" id="factoryId"/>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">配件主图：</label>
                        <div class="col-sm-8">
                            <input type="hidden" name="partsImages" required>
                            <div class="file-loading">
                                <input class="form-control file-upload" id="partsImages" name="file" type="file">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">主图视频：</label>
                        <div class="col-sm-8">
                            <input type="hidden" name="partsVideourl">
                            <div class="file-loading">
                                <input class="form-control file-upload" id="partsVideourl" name="file" type="file">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品名称：</label>
                        <div class="col-sm-8">
                            <input name="partsName" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品分类：</label>
                        <div class="col-sm-8">
                            <input name="partsTypeName" onclick="selectTypeTree()" id="treeName" type="text" placeholder="请选择所属分类" class="form-control" readonly required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">所属厂家：</label>
                        <div class="col-sm-8">
                            <input id="factoryName" name="factoryName" placeholder="请选择所属厂家" class="form-control" type="text" onclick="selectFactory()" readonly required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品类型：</label>
                        <div class="col-sm-8">
                            <select name="partsClassification" class="form-control m-b" th:with="type=${@dict.getType('parts_class')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品单位（会长端）：</label>
                        <div class="col-sm-8">
                            <input name="partsUnit" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品单位（店铺端）：</label>
                        <div class="col-sm-8">
                            <input name="partsStoreUnit" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品品牌：</label>
                        <div class="col-sm-8">
                            <select name="partsDistinguish" class="form-control m-b" th:with="type=${@dict.getType('parts_brand')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">是否有补助金：</label>
                        <div class="col-sm-8">
                            <select name="partsHasGrant" class="form-control m-b" th:with="type=${@dict.getType('zsyh_yesno')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">是否热门推荐：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isHotPush_' + dict.dictCode}" name="isHotPush" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isHotPush_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">会长是否上架：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowProvince_' + dict.dictCode}" name="isShowProvince" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isShowProvince_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">配件店是否上架：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowCity_' + dict.dictCode}" name="isShowCity" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isShowCity_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">维修师傅是否上架：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowWorker_' + dict.dictCode}" name="isShowWorker" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isShowWorker_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <!--<div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品描述(会长端)：</label>
                        <div class="col-sm-8">
                            <textarea name="partsDetails" class="form-control" required></textarea>
                        </div>
                    </div>
                </div>-->
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">是否包邮：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isPost_' + dict.dictCode}" name="isPost" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isPost_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品描述(店铺端)：</label>
                        <div class="col-sm-8">
                            <textarea name="partsStoreDetails" class="form-control" required></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">注意事项：</label>
                        <div class="col-sm-8">
                            <input type="hidden" class="form-control" name="partsAttention">
                            <div class="summernote" id="partsAttention"></div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">使用说明：</label>
                        <div class="col-sm-8">
                            <input type="hidden" class="form-control" name="partsInstructions">
                            <div class="summernote" id="partsInstructions"></div>
                        </div>
                    </div>
                </div>
            </div>

            <!--<div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">人口销售额比例：</label>
                        <div class="col-sm-8">
                            <input name="populationSalesRatio" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">销售额定金比例：</label>
                        <div class="col-sm-8">
                            <input name="salesPaymentRatio" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>-->

            <div class="row">

                <!--<div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">大区合作政策：</label>
                        <div class="col-sm-8">
                            <textarea name="cooperationPolicy" class="form-control"></textarea>
                        </div>
                    </div>
                </div>-->
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">补助金赔付条件：</label>
                        <div class="col-sm-8">
                            <!--<input type="hidden" class="form-control" name="partsDamageDetails">
                            <div class="summernote" id="partsDamageDetails"></div>-->
                            <textarea name="partsDamageDetails" class="form-control"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <!--<div class="form-group">
                <label class="col-sm-3 control-label">配件编码：</label>
                <div class="col-sm-8">
                    <input name="partsNumber" class="form-control" type="text">
                </div>
            </div>-->
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">配件品牌：</label>
                <div class="col-sm-8">
                    <input name="partsBrand" class="form-control" type="text">
                </div>
            </div>-->


            <!--<div class="form-group">
                <label class="col-sm-3 control-label">配件详细信息：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="partsRemarks">
                    <div class="summernote" id="partsRemarks"></div>
                </div>
            </div>-->
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">是否今日热卖：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                        <input type="radio" th:id="${'isTodayHot_' + dict.dictCode}" name="isTodayHot" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'isTodayHot_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>-->
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">是否新品推荐：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                        <input type="radio" th:id="${'isNewPush_' + dict.dictCode}" name="isNewPush" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'isNewPush_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否好物优选：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                        <input type="radio" th:id="${'isGoodChoice_' + dict.dictCode}" name="isGoodChoice" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'isGoodChoice_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>-->


            <!--<div class="form-group">
                <label class="col-sm-3 control-label">订购最低数量：</label>
                <div class="col-sm-8">
                    <input name="partsQuantity" class="form-control" type="text">
                </div>
            </div>-->
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">排序数字越大，排序约靠前：</label>
                <div class="col-sm-8">
                    <input name="soft" class="form-control" type="text">
                </div>
            </div>-->




            <!--<div class="form-group">
                <label class="col-sm-3 control-label">省级会长图文详情：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="agentRemakes">
                    <div class="summernote" id="agentRemakes"></div>
                </div>
            </div>-->
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">维修安装指南：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="partsInstallationguide">
                    <div class="summernote" id="partsInstallationguide"></div>
                </div>
            </div>-->

            <!--<div class="form-group">
                <label class="col-sm-3 control-label">配件图标：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="partsLogo">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="partsLogo" name="file" type="file">
                    </div>
                </div>
            </div>-->

            <!--<div class="form-group">
                <label class="col-sm-3 control-label">淘宝连接：</label>
                <div class="col-sm-8">
                    <textarea name="partsTaobaourl" class="form-control"></textarea>
                </div>
            </div>-->

            <!--<div class="form-group">
                <label class="col-sm-3 control-label">是否显示属性信息：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                        <input type="radio" th:id="${'isViewAttrs_' + dict.dictCode}" name="isViewAttrs" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'isViewAttrs_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>-->
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">赔付条件：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="partsConditions">
                    <div class="summernote" id="partsConditions"></div>
                </div>
            </div>-->


            <!--<div class="form-group">
                <label class="col-sm-3 control-label">返点方式 1差额 2百分比：</label>
                <div class="col-sm-8">
                    <select name="partsRebateType" class="form-control m-b" th:with="type=${@dict.getType('parts_rebate')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>-->
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <div class="row" style="height: 20px;">
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/parts"
        var isShowProviceDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isShowCityDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isShowWorkerDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isPostDatas = [[${@dict.getType('zsyh_yesno')}]];
        $("#form-parts-add").validate({
            focusCleanup: true
        });

        /* 选择所属分类 */
        function selectTypeTree() {
            var treeId = $("#treeId").val();
            var typeId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url =ctx + "zsyh/partstype/selectTypeTree/" + $("#treeId").val();
            var options = {
                title: '选择所属分类',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            debugger;
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-parts-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/uploadOSS',
            maxFileCount: 1,
            showUpload:false,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        }).on("filebatchselected", function(event, files) {
            $(this).fileinput("upload");
        })

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/uploadOSS",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });

        function selectFactory() {
            var url =  ctx+"zsyh/factory/selectFactory";
            layer.open({
                type: 2,
                area: ['800px', '700px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "选择厂家",
                content:  url,
                closeBtn: 1,
                // 弹层外区域关闭
                shadeClose: true,
                end: function(){
                    //location.reload();
                },
                cancel: function(index) {
                    //location.reload();
                }
            });
        }
        
    </script>
</body>
</html>